package mipo.top.system.controller;


import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.system.domain.Permission;
import mipo.top.system.query.PermissionQuery;
import mipo.top.system.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @GetMapping
    public List<Permission> sad(){
        return permissionService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody Permission permission){
        try {
            if(permission.getId()==null){
                permissionService.save(permission);
            }else{
                permissionService.update(permission);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        permissionService.remove(id);
    }

    @PostMapping
    public PageUtil<Permission> asp(@RequestBody PermissionQuery permissionQuery){
        return permissionService.queryData(permissionQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        permissionService.patchremove(ids);
    }
}
